//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XWorld.h>
///	@path	~/src/scene/xworld/
///	@date	2007/12/19
///	@desc	Largest level of scene structure.

#pragma once

#include "xeres.h"

#include "lib/math/math_ext.h"
#include "lib/math/vector.h"
#include "lib/math/matrix.h"
#include "lib/math/rect.h"
#include "lib/utilities/string.h"
#include "lib/utilities/dict.h"

#include "object/IObject.h"

#include "scene/IScene.h"

namespace xeres {

	// forward declaration

	//  spacing structure
	class XWorld;
	class XSpace;
	class XChunk;
	class XSlice;
	class XShell;
	class XBound;

	// connection structure
	class XBorder;
	class XPortal;

	// coordinate system
	enum XCoordSystem
	{
		XCOORD_WORLD ,	// we're using world-wide coordinate
		XCOORD_SPACE ,	// we're using local space coordinate
		XCOORD_CELL ,	// we're using cell's coordinate
		XCOORD_last
	};

	/*!
		\class	XWorld
		\brief	Largest level of scene structure, contains some spaces that connected by XBorder.
				XWorld is holding by game logic, used to manipulate which scene we're in.
	*/
	class XWorld : public IScene
	{
	public:

		/// \ctor
		XWorld( void );

		/// \dtor
		virtual ~XWorld( void );

		DECL_IOBJECT_CLASS( XWorld , IScene );

	//@ interface

		/*!
			\brief		Initialize scene by config.
		*/
		virtual bool Initialize( RefWeak<IData> config );

		/*!
			\brief		Finalize scene.
		*/
		virtual void Finalize( void );

		/*!
			\brief		Start to load scene, schedule children.
		*/
		virtual void Preload( void );

		/*!
			\brief		Called when player is about to enter the scene.
		*/
		virtual void Enter( const Vector<float>& position_in_world );
		
		/*!
			\brief		Keep scene update.
		*/
		virtual void Tick( const Frame& frame );

		/*!
			\brief		Make presentation of scene.
		*/
		virtual void Present( ScenePresentation& sp );

		/*!
			\brief		Give a chance to process scene at synchronized point.
		*/
		virtual void Synchronized( void );

		/*!
			\brief		Get axis aligned bounding box.
		*/
		virtual const Box<float>& GetBound( void );

	// @ local

		/*!
			\brief		Construct a world by a description.
		*/
		bool Construct( RefWeak<IData> desc );

	private:

	//@ data

		// status
		bool							m_active;		// indicates world is active
		bool							m_spare0[3];


		// holds a list of spaces

		// current space
		RefWeak<XSpace>				m_currentSpace;

		// containing space
		dict< WString , Ref<XSpace> >	m_spaces;

		// borders
		std::vector< Ref<XBorder> >		m_borders;
	};

} // namespace xeres
